package com.hzit.common.util;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ResponseUtil {
	public static void out(HttpServletResponse response,R r){
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			//1. 设置响应码是ok
			response.setStatus(HttpStatus.OK.value());
			//2. 设置响应输出
			response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
			// response.getWriter().println(JSON.toJSONString(r));
			// response.getWriter().flush();
			objectMapper.writeValue(response.getWriter(),r);
			// User user = objectMapper.readValue(request.getInputStream(),User.class);

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
